package com.ssm.chageunit.logmanager;

import java.awt.*;
import javax.swing.*;


public class DataUI extends JPanel {
	protected final static String names[]={"VersionNumber",
		"Modify_by","Mtime","Mlog","source","MMerge","Mchild","MMerge2","Mchild2",
		"MMerge3","Mchild3"};
	protected JLabel labels[];
	protected JTextField fields[];
	protected JButton doTask1;
	protected JPanel innerPanelCenter,innerPanelSouth;
	
	protected int size;
	
	public static final int VersionNumber=0,Modify_by=1,Mtime=2,
		Mlog=3,source=4,MMerge=5,Mchild=6,MMerge2=7,Mchild2=8,MMerge3=9,Mchild3=10;
	
	public DataUI(int mySize)
	{
		size=mySize;
		labels=new JLabel[size];
		fields=new JTextField[size];
		
		for(int count=0;count<labels.length;count++)
			labels[count]=new JLabel(names[count]);
		
		for(int count=0;count<fields.length;count++)
			fields[count]=new JTextField();
		
		innerPanelCenter=new JPanel();
		innerPanelCenter.setLayout(new GridLayout(size,10));
		
		for(int count=0;count<size;count++){
			innerPanelCenter.add(labels[count]);
			innerPanelCenter.add(fields[count]);
		}
		
		doTask1=new JButton();
		
		innerPanelSouth=new JPanel();
		innerPanelSouth.add(doTask1);
		
		setLayout(new BorderLayout());
		add(innerPanelCenter,BorderLayout.CENTER);
		add(innerPanelSouth,BorderLayout.SOUTH);
		
		validate();
		}
	
	public JButton getDoTask1Button()
	{
		return doTask1;
	}
	public JTextField[] getFields()
	{
		return fields;
	}
	
	public void clearFields()
	{
		for(int count=0;count<size;count++)
			fields[count].setText("");
	}
	
	public void setFieldValues(String strings[])
		throws IllegalArgumentException
	{
		if(strings.length != size)
			throw new IllegalArgumentException("There must be"+
					size+"Strings in the array");
		
		for(int count=0;count<size;count++)
			fields[count].setText(strings[count]);
	}
	
	public String[] getFieldValues()
	{
		String values[]=new String[size];
		
		for(int count=0;count<size;count++)
			values[count]=fields[count].getText();
		
		return values;
	}
}
